/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.rbh.risk.entity;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

/**
 *
 * @author IT-Mafia
 */
@Entity
@Table(name = "rbh_risk_sub_event")
@XmlRootElement
public class SubEvent implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "SUB_EVENT_ID", unique = true, nullable = false, columnDefinition = "smallint UNSIGNED")
    private Short subEventId;
    @Column(name = "SUB_EVENT_DESCRIPTION", length = 1024)
    private String subEventDescription;
    @Basic(optional = false)
    @Column(name = "SUB_EVENT_NAME", length = 100)
    private String subEventName;
    @Basic(optional = false)
    @Column(name = "SUB_EVENT_ORDER_NUMBER", columnDefinition = "tinyint UNSIGNED default 0", nullable = false)
    private short subEventOrderNumber;
    @Basic(optional = false)
    @Column(name = "SUB_EVENT_STATUS", columnDefinition = "boolean default true", nullable = false)
    private boolean subEventStatus;
    @JoinColumn(name = "RBH_RISK_MAIN_EVENT", referencedColumnName = "MAIN_EVENT_ID")
    @ManyToOne(fetch = FetchType.LAZY)
    private MainEvent mainEvent;
    @OneToMany(mappedBy = "subEvent", fetch = FetchType.LAZY)
    @Cascade({CascadeType.DETACH})
    private List<RiskData> riskDataList;

    public SubEvent() {
    }

    public SubEvent(Short subEventId) {
        this.subEventId = subEventId;
    }

    public SubEvent(Short subEventId, String subEventName, short subEventOrderNumber, boolean subEventStatus) {
        this.subEventId = subEventId;
        this.subEventName = subEventName;
        this.subEventOrderNumber = subEventOrderNumber;
        this.subEventStatus = subEventStatus;
    }

    public Short getSubEventId() {
        return subEventId;
    }

    public void setSubEventId(Short subEventId) {
        this.subEventId = subEventId;
    }

    public String getSubEventDescription() {
        return subEventDescription;
    }

    public void setSubEventDescription(String subEventDescription) {
        this.subEventDescription = subEventDescription;
    }

    public String getSubEventName() {
        return subEventName;
    }

    public void setSubEventName(String subEventName) {
        this.subEventName = subEventName;
    }

    public short getSubEventOrderNumber() {
        return subEventOrderNumber;
    }

    public void setSubEventOrderNumber(short subEventOrderNumber) {
        this.subEventOrderNumber = subEventOrderNumber;
    }

    public boolean getSubEventStatus() {
        return subEventStatus;
    }

    public void setSubEventStatus(boolean subEventStatus) {
        this.subEventStatus = subEventStatus;
    }

    public MainEvent getMainEvent() {
        return mainEvent;
    }

    public void setMainEvent(MainEvent mainEvent) {
        this.mainEvent = mainEvent;
    }

    @XmlTransient
    public List<RiskData> getRiskDataList() {
        return riskDataList;
    }

    public void setRiskDataList(List<RiskData> riskDataList) {
        this.riskDataList = riskDataList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (subEventId != null ? subEventId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof SubEvent)) {
            return false;
        }
        SubEvent other = (SubEvent) object;
        if ((this.subEventId == null && other.subEventId != null) || (this.subEventId != null && !this.subEventId.equals(other.subEventId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return this.subEventId + "";
    }
}
